package com.cjg.javaBasics;

import java.util.Scanner;

public class Calculator {
    public static void main(String[] args) {

        String exit ="a";
        while(exit=="a"){
            System.out.println("请输入+-*/ 输入e退出");
            Scanner scanner = new Scanner(System.in);
            String next = scanner.next();
            switch (next){
                case "+" :
                    System.out.println("输入两个数 以回车分割");
                    Scanner scanner1 = new Scanner(System.in);
                    double v = scanner1.nextDouble();
                    double v1 = scanner1.nextDouble();
                    //获取多个
           /*     String[] s = scanner1.nextLine().split(" ");
                int[] i =new int[s.length];
                for (int j = 0; j <s.length ; j++) {
                    i[j]=Integer.parseInt(s.[j]);
                }*/
                    System.out.println(add(v,v1));
                    break;
                case "-" :
                    System.out.println("输入两个数 以回车分割");
                    Scanner scanner2 = new Scanner(System.in);
                    double z = scanner2.nextDouble();
                    double z1 = scanner2.nextDouble();
                    System.out.println(substract(z,z1));
                    break;
                case "*" :
                    System.out.println("输入两个数 以回车分割");
                    Scanner scanner3 = new Scanner(System.in);
                    double q = scanner3.nextDouble();
                    double q1 = scanner3.nextDouble();
                    System.out.println(multiply(q,q1));
                    break;
                case "/" :
                    System.out.println("输入两个数 以回车分割");
                    Scanner scanner4 = new Scanner(System.in);
                    double w = scanner.nextDouble();
                    double w1 = scanner4.nextDouble();
                    System.out.println(divide(w,w1));
                    break;
                case  "e" :
                    exit="e";
                    break;


            }
        }




    }



    public static double add(double ... doubles){
        double sum = 1.0;
        for (int i = 0; i <doubles.length ; i++) {
            sum=sum*doubles[i];
        }
        return sum;
    }
    public static double substract(double a,double ... doubles){
        double sum = a;
        for (int i = 0; i <doubles.length ; i++) {
            sum=sum-doubles[i];
        }
        return sum;
    }
    public static double multiply(double ... doubles){
        double sum = 1.0;
        for (int i = 0; i <doubles.length ; i++) {
            sum=sum*doubles[i];
        }
        return sum;
    }
    public static double divide(double a,double ... doubles){
        double sum = a;
        for (int i = 0; i <doubles.length ; i++) {
            sum=sum/doubles[i];
        }
        return sum;
    }
}
